//
//  CollectionViewCell.swift
//  ReadHub
//
//  Created by testypp on 2017/12/20.
//  Copyright © 2017年 longyiqun. All rights reserved.
//

import Foundation
import UIKit

class CollectionViewCell: UICollectionViewCell {
	
	let titleLabel = UILabel()
	let mainView = UIView()
    let mainIMG = UIImageView()
	
	override init(frame: CGRect) {
		super.init(frame: frame)
		
		// subview config
		titleLabel.textAlignment = .left
		mainView.backgroundColor = UIColor.white
		mainView.layer.cornerRadius = 3
		
		// prepare subviews for layout
		contentView.addSubview(mainView)
		mainView.translatesAutoresizingMaskIntoConstraints = false
		mainView.addSubview(titleLabel)
		titleLabel.translatesAutoresizingMaskIntoConstraints = false
		mainView.layoutMargins = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        
        mainIMG.translatesAutoresizingMaskIntoConstraints = false
        mainIMG.contentMode = .scaleAspectFit
		mainIMG.layer.cornerRadius = 10.0
		mainIMG.layer.masksToBounds = true;
        
        mainView.addSubview(mainIMG)
		
		NSLayoutConstraint.activate([
			mainView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
			mainView.topAnchor.constraint(equalTo: contentView.topAnchor),
			mainView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
			mainView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
			
			titleLabel.leadingAnchor.constraint(equalTo: mainView.layoutMarginsGuide.leadingAnchor),
			titleLabel.bottomAnchor.constraint(equalTo: mainView.layoutMarginsGuide.bottomAnchor),
            
            mainIMG.leadingAnchor.constraint(equalTo: mainView.leadingAnchor),
            mainIMG.topAnchor.constraint(equalTo: mainView.topAnchor),
            mainIMG.trailingAnchor.constraint(equalTo: mainView.trailingAnchor),
            mainIMG.bottomAnchor.constraint(equalTo: mainView.bottomAnchor)
			])
	}
	
	required init?(coder aDecoder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
}
